package com.yuanfeng.goods.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.commoms.aspect.UserPermissionsResult;
import com.yuanfeng.commoms.aspect.UserService;
import com.yuanfeng.commoms.config.PermissionsConstant;
import com.yuanfeng.commoms.config.YFConfig;
import com.yuanfeng.commoms.constant.CommonType;
import com.yuanfeng.commoms.dto.userms.UserInfoDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.DateUtils;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.RedisUtil;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.goods.ManageGdsCommonResultVO;
import com.yuanfeng.commoms.vo.goods.ManageShopBaseQueryResultVO;
import com.yuanfeng.commoms.vo.goods.ManageTransportAreaResultVO;
import com.yuanfeng.commoms.vo.goods.ManageTransportTemplateResultVO;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import com.yuanfeng.goods.dto.*;
import com.yuanfeng.goods.entity.GoodsDraftEntity;
import com.yuanfeng.goods.mapper.GoodsDraftMapper;
import com.yuanfeng.goods.service.GoodsDraftService;
import com.yuanfeng.goods.vo.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.*;

/**
 * @ClassName GoodsDraftServiceImpl
 * @Description 草稿箱
 * @Author liulh
 * @Date 2023/8/11 9:20
 * @Version 1.0
 **/
@Service
public class GoodsDraftServiceImpl extends ServiceImpl<GoodsDraftMapper, GoodsDraftEntity>
        implements GoodsDraftService {

    @Override
    public ResponseResult queryDraft(Map<String, Object> param) {
        String token = (String) param.get("token");
        // 根据code存储用户信息
        UserInfoVO userInfo = ParseTokenUtils.getUserInfoByToken(token);
        if (null == userInfo) {
            return ResponseResult.fail(BizCodeEnume.INSUFFICIENT_PERMISSIONS);
        }
        String shopId = (String) param.get("shopId");
        Integer catId = (Integer) param.get("catId");

        List<ManageGdsCommonQueryResultDraftVO> drafts = new ArrayList<>();
        List<ManageGdsCommonQueryResultStrVO> strList = this.baseMapper.queryDraft(shopId, catId);
        Map<String, Object> map = new HashMap<>();
        if (strList != null && strList.size() > 0) {
            for (ManageGdsCommonQueryResultStrVO str : strList) {
                ManageGdsCommonQueryResultVO manageGdsCommonQueryResult = new ManageGdsCommonQueryResultVO();
                ManageGdsCommonPublishDTO manageGdsCommonPublish = JSONObject.parseObject(str.getDraftContent(), ManageGdsCommonPublishDTO.class);
                List<ManageGdsBaseAddResultVO> gdsBases = new ArrayList<>();
                if(!CollectionUtils.isEmpty( manageGdsCommonPublish.getGdsBases())){
                    for (ManageGdsBaseAddPublishDTO push : manageGdsCommonPublish.getGdsBases()) {
                        ManageGdsBaseAddResultVO result = new ManageGdsBaseAddResultVO();
                        result.setBrandId(push.getBrandId());
                        result.setCatId(push.getCatId());
                        result.setCommission(push.getCommission());
                        result.setCommodityBarTypeCode(push.getCommodityBarTypeCode());
                        result.setCommonId(push.getCommonId());
                        result.setDw(push.getDw());
                        result.setGoodsName(push.getGoodsName());
                        result.setGoodsAlarm(push.getGoodsAlarm());
                        result.setGoodsBabyPrice(push.getGoodsBabyPrice());
                        result.setGoodsBarcode(push.getGoodsBarcode());
                        result.setGoodsCode(push.getGoodsCode());
                        result.setGoodsCostPrice(push.getGoodsCostPrice());
                        result.setGoodsCubage(push.getGoodsCubage());
                        result.setGoodsImage(push.getGoodsImage());
                        result.setGoodsIsRecommend(push.getGoodsIsRecommend());
                        result.setGoodsIsShelves(push.getGoodsIsShelves());
                        result.setGoodsMarketPrice(push.getGoodsMarketPrice());
                        result.setGoodsMaxSale(push.getGoodsMaxSale());
                        result.setGoodsMinSale(push.getGoodsMinSale());
                        result.setGoodsPrice(push.getGoodsPrice());
                        result.setGoodsPromotionTips(push.getGoodsPromotionTips());
                        result.setGoodsSendBack(push.getGoodsSendBack());
                        result.setGoodsShopGateStock(push.getGoodsShopGateStock());
                        result.setGoodsSpec(push.getGoodsSpec());
                        result.setGoodsSpecValue(push.getGoodsSpecValue());
                        result.setGoodsStock(push.getGoodsStock());
                        if (StringUtils.isNotEmpty(push.getGoodsVolume())) {
                            BigDecimal goodsVolume = new BigDecimal(push.getGoodsVolume());
                            result.setGoodsVolume(goodsVolume);
                        }
                        if (push.getIsEnquiry() != null && push.getIsEnquiry() == true) {
                            result.setIsEnquiry(1);
                        } else {
                            result.setIsEnquiry(0);
                        }
                        result.setIsUse(push.getIsUse());
                        result.setMerchantCode(push.getMerchantCode());
                        result.setMoq(push.getMoq());
                        result.setSellingPoint(push.getSellingPoint());
                        result.setShopId(Integer.valueOf(shopId));
                        result.setShopName(push.getShopName());
                        result.setSpecId(push.getSpecId());
                        result.setSpecName(push.getSpecName());
                        result.setSpecValue(push.getGoodsSpecValue());
                        result.setTaxInclusiveAmount(push.getTaxInclusiveAmount());
                        result.setTaxRate(push.getTaxRate());
                        result.setTypeId(push.getTypeId());

                        List<GoodsStepPriceVO> stepPrices = new ArrayList<>();
                        if(!CollectionUtils.isEmpty(push.getGdsStepPriceList())){
                            for (ManageGdsStepPriceDTO prices : push.getGdsStepPriceList()) {
                                GoodsStepPriceVO stepPrice = new GoodsStepPriceVO();
                                stepPrice.setGdsStepPrices(prices.getGdsStepPrices());
                                stepPrice.setGradeId(prices.getGradeId());
                                stepPrice.setShopId(Integer.valueOf(shopId));
                                stepPrice.setPrice(prices.getPrice());
                                stepPrice.setId(prices.getId());
                                stepPrice.setNumCount(prices.getMumCount());
                                stepPrices.add(stepPrice);
                            }
                        }

                        result.setStepPrices(stepPrices);
                        gdsBases.add(result);
                    }
                }
                manageGdsCommonQueryResult.setGdsBases(gdsBases);

                ManageGdsCommonResultVO commonResult = new ManageGdsCommonResultVO();
                commonResult.setAfterService(manageGdsCommonPublish.getAfterService());
                commonResult.setAfterServiceList(manageGdsCommonPublish.getAfterServiceList());
                commonResult.setBrandId(manageGdsCommonPublish.getBrandId());
                commonResult.setBrandName(manageGdsCommonPublish.getBrandName());
                commonResult.setCatId(manageGdsCommonPublish.getCatId());
                commonResult.setCatIds(manageGdsCommonPublish.getCatIds());
                commonResult.setCatName(manageGdsCommonPublish.getCatName());
                commonResult.setCommonAddTime(manageGdsCommonPublish.getCommonAddTime());
                commonResult.setCommonAlarm(manageGdsCommonPublish.getCommonAlarm());
                commonResult.setCommonBabyPrice(manageGdsCommonPublish.getCommonBabyPrice());
                commonResult.setCommonCostPrice(manageGdsCommonPublish.getCommonCostPrice());
                commonResult.setCommonCubage(manageGdsCommonPublish.getCommonCubage());
                commonResult.setCommonFormatidBottom(manageGdsCommonPublish.getCommonFormatidBottom());
                commonResult.setCommonFormatidTop(manageGdsCommonPublish.getCommonFormatidTop());
                commonResult.setCommonName(manageGdsCommonPublish.getCommonName());
                commonResult.setCommonImage(manageGdsCommonPublish.getCommonImage());
                commonResult.setCommonIsRecommend(manageGdsCommonPublish.getCommonIsRecommend());
                commonResult.setCommonIsShopTake(manageGdsCommonPublish.getCommonIsShopTake());
                commonResult.setCommonLimit(manageGdsCommonPublish.getCommonLimit());
                commonResult.setCommonMarketPrice(manageGdsCommonPublish.getCommonMarketPrice());
                commonResult.setCommonPackingList(manageGdsCommonPublish.getCommonPackingList());
                commonResult.setCommonPrice(manageGdsCommonPublish.getCommonPrice());
                commonResult.setCommonPromotionTips(manageGdsCommonPublish.getCommonPromotionTips());
                commonResult.setCommonProperty(manageGdsCommonPublish.getCommonProperty());
                commonResult.setCommonSellTime(manageGdsCommonPublish.getCommonSellTime());
                commonResult.setCommonService(manageGdsCommonPublish.getCommonService());
                commonResult.setCommonSpecName(manageGdsCommonPublish.getCommonSpecName());
                commonResult.setCommonSpecValue(manageGdsCommonPublish.getCommonSpecValue());
                commonResult.setCommonState(manageGdsCommonPublish.getCommonState());
                commonResult.setCommonStock(manageGdsCommonPublish.getCommonStock());
                commonResult.setCommonType(manageGdsCommonPublish.getCommonType());
                commonResult.setCommonVideo(manageGdsCommonPublish.getCommonVideo());
                commonResult.setCustomInformation(manageGdsCommonPublish.getCustomInformation());
                commonResult.setCustomInformationList(manageGdsCommonPublish.getCustomInformationList());
                commonResult.setDeliveryDate(manageGdsCommonPublish.getDeliveryDate());
                commonResult.setDw(manageGdsCommonPublish.getDw());
                commonResult.setGoodsOrderDate(manageGdsCommonPublish.getGoodsOrderDate());
                commonResult.setGoodsRecommendedMaxPrice(manageGdsCommonPublish.getGoodsRecommendedMaxPrice());
                commonResult.setGoodsRecommendedMinPrice(manageGdsCommonPublish.getGoodsRecommendedMinPrice());
                commonResult.setGoodsSendBack(manageGdsCommonPublish.getGoodsSendBack());
                commonResult.setGoodsType(manageGdsCommonPublish.getGoodsType());
                commonResult.setHotState(manageGdsCommonPublish.getHotState());
                commonResult.setPastDue(manageGdsCommonPublish.getPastDue());
                commonResult.setDeliveryTime(manageGdsCommonPublish.getDeliveryTime());
                if (!StringUtils.isEmpty(manageGdsCommonPublish.getPeriodOfValidity())) {
                    Date date = DateUtils.parseCNDate(manageGdsCommonPublish.getPeriodOfValidity());
                    commonResult.setPeriodOfValidity(date);
                }
                commonResult.setRestrictionHours(manageGdsCommonPublish.getRestrictionHours());
                commonResult.setRestrictionTimes(manageGdsCommonPublish.getRestrictionTimes());
                commonResult.setSellingPoint(manageGdsCommonPublish.getSellingPoint());
                commonResult.setShopCatId(manageGdsCommonPublish.getShopCatId());
                commonResult.setShopId(manageGdsCommonPublish.getShopId()==null?null:Integer.valueOf(manageGdsCommonPublish.getShopId()));
                commonResult.setShopName(manageGdsCommonPublish.getShopName());
                commonResult.setShopSelfSupport(manageGdsCommonPublish.getShopSelfSupport());
                commonResult.setShopStatus(manageGdsCommonPublish.getShopStatus());
                commonResult.setSpecParam(JSON.toJSONString(manageGdsCommonPublish.getSpecParam()));
                commonResult.setSpecParamList(manageGdsCommonPublish.getSpecParam());
                commonResult.setTransportAreaId(manageGdsCommonPublish.getTransportAreaId());
                if (manageGdsCommonPublish.getTransportAreaId() != null) {
                    ManageTransportAreaResultVO transportAreas = this.baseMapper.selectAreaById(manageGdsCommonPublish.getTransportAreaId());
                    if (transportAreas != null) {
                        commonResult.setTransportAreas(transportAreas);
                    }
                }
                commonResult.setTransportTemplate(manageGdsCommonPublish.getTransportTemplate());
                if (manageGdsCommonPublish.getTransportTemplate() != null) {
                    ManageTransportTemplateResultVO transportTemplate = this.baseMapper.selectTemplateById(manageGdsCommonPublish.getTransportTemplate());
                    if (transportTemplate != null) {
                        commonResult.setTransportTemplates(transportTemplate);
                    }
                }
                commonResult.setTransportTypeId(manageGdsCommonPublish.getTransportTypeId());
                commonResult.setType(manageGdsCommonPublish.getType());
                commonResult.setTypeId(manageGdsCommonPublish.getTypeId());
                commonResult.setVirtualGoods(manageGdsCommonPublish.getVirtualGoods());
                manageGdsCommonQueryResult.setCommonResult(commonResult);

                manageGdsCommonQueryResult.setGoodsCommonDetail(manageGdsCommonPublish.getGoodsCommonDetail());
                manageGdsCommonQueryResult.setGoodsImages(manageGdsCommonPublish.getGoodsImages());
                manageGdsCommonQueryResult.setManageGdsGoodsConfig(manageGdsCommonPublish.getManageGdsGoodsConfig());
                if (!CollectionUtils.isEmpty(manageGdsCommonPublish.getGoodsCatIdList())) {
                    List<MerchantShopGoodsCatDTO> shopGoodsCatList = this.baseMapper.queryShopGoodsCatList(manageGdsCommonPublish.getGoodsCatIdList());
                    for (MerchantShopGoodsCatDTO merchantShopGoodsCat : shopGoodsCatList) {
                        if (merchantShopGoodsCat.getParentId() != 0) {
                            String catName = this.baseMapper.queryShopGoodsCatName(merchantShopGoodsCat.getParentId());
                            merchantShopGoodsCat.setShopGoodsCatName(catName + "/" + merchantShopGoodsCat.getShopGoodsCatName());
                        }
                    }
                    manageGdsCommonQueryResult.setShopGoodsCatList(shopGoodsCatList);
                }
                manageGdsCommonQueryResult.setGoodsCatList(manageGdsCommonPublish.getGoodsCatIdList());

                ManageGdsCommonQueryResultDraftVO draft = new ManageGdsCommonQueryResultDraftVO();
                draft.setManageGdsCommonQueryResult(manageGdsCommonQueryResult);
                draft.setDraftId(str.getDraftId());
                draft.setDraftName(str.getDraftName());
                draft.setCatId(str.getCatId());
                draft.setShopId(str.getShopId());
                draft.setCreateTime(str.getCreateTime());
                drafts.add(draft);
            }
            map.put("list", drafts);
            map.put("totalCount", this.baseMapper.queryDraftCount(shopId, catId));
        } else {
            map.put("list", drafts);
            map.put("totalCount", 0);
        }

        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL.getMsg(), map);
    }

    @Override
    public ResponseResult deleteDraft(Map<String, Object> param) {
        String token = (String) param.get("token");
        // 根据code存储用户信息
        String userInfoStr = RedisUtil.get(YFConfig.YF_USER_TOKEN_USER + token);
        UserInfoDTO dto = JSON.parseObject(userInfoStr, UserInfoDTO.class);
        UserInfoVO userInfo = dto.getUser();
        if (null == userInfo.getShopId()) {
            return ResponseResult.fail(BizCodeEnume.INSUFFICIENT_PERMISSIONS);
        }
        Integer draftId = (Integer) param.get("draftId");
        this.baseMapper.deleteById(draftId);
        return ResponseResult.success(BizCodeEnume.DELETE_SUCCESS);
    }

    @Override
    @Transactional
    public ResponseResult addGoodsToDraft(Map<String, Object> param) {
        String token = (String) param.get("token");
        String draftName = (String) param.get("draftName");
        Object draftContent = param.get("draftContent");
        String str = JSONObject.toJSONString(draftContent);
        ManageGdsCommonPublishDTO param2 = JSONObject.parseObject(str, ManageGdsCommonPublishDTO.class);
        try {
            // 权限判断
            UserPermissionsResult userPermissionsResult = UserService
                    .judgePermissions(PermissionsConstant.SERLLER_SHOP_SETSHOP, token);
            if (!userPermissionsResult.getFlag()) {
                return ResponseResult.fail(BizCodeEnume.INSUFFICIENT_PERMISSIONS);
            }
            String shopId = userPermissionsResult.getShopId();
            param2.setShopId(shopId);
            param2.setCommonUpdateBy(userPermissionsResult.getUserId());
            param2.setCommonUpdateTime(new Date());
            //	序列化数组自定义信息
            String json = JSON.toJSONString(param2.getCustomInformationList());
            param2.setCustomInformation(json);
            //	序列化数组自定义信息
            String jsonString = JSON.toJSONString(param2.getAfterServiceList());
            param2.setAfterService(jsonString);
            // 初始化默认值
            // 判断是否放入仓库
            if (param2.getCommonState() == null || param2.getCommonState() == 0) {
                param2.setCommonState(0);
            }
            param2.setCommonCubage(new BigDecimal(0));
            param2.setGoodsId("0");
            param2.setCommonVerify(10);
            param2.setCommonStock(0);
            param2.setCommonAddTime(new Date());
            param2.setCommonSellTime(DateUtils.stringToTime(param2.getCommonSellTimeStr()));
            if (!CollectionUtils.isEmpty(param2.getGoodsImages())) {
                if (!param2.getGoodsImages().get(0).getMerchantGoodsImages().isEmpty()) {
                    String image = param2.getGoodsImages().get(0).getMerchantGoodsImages().get(0).getImagesImage();
                    param2.setCommonImage(image);
                }
            }
            // 获取店铺区域id
            ManageShopBaseQueryResultVO shopBaseQueryResult = this.baseMapper.selectByShopId2(param2.getShopId());

            param2.setDistrictId(shopBaseQueryResult.getDistrictId());
            param2.setShopName(shopBaseQueryResult.getShopName());
            if (shopBaseQueryResult.getShopSelfSupport() == "false") {
                param2.setShopSelfSupport(0);
            } else {
                param2.setShopSelfSupport(1);
            }
            // 判断主图类型
            if (StringUtils.isNotEmpty(param2.getCommonVideo())) {
                param2.setType(2);
            }

            param2.setShopStatus(shopBaseQueryResult.getShopStatus());
            param2.setCommonSpecValue("");
            // 将规格 和 规格值保存到数据库 规格跟着商品走
            if (null != param2.getSpecParam()) {
                param2.setSpecParamJson(JSON.toJSONString(param2.getSpecParam()));
            }

            if (null != userPermissionsResult.getShopType()) {
                if (userPermissionsResult.getShopType().equals(CommonType.ShopType.SUPPLY_SHOP.getCode())) {
                    param2.setGoodsType(2);
                }
            }
            if (null == param2.getVirtualGoods()) {
                param2.setVirtualGoods(1);
            }
            if (!StringUtils.isNotBlank(param2.getPeriodOfValidity())) {
                param2.setPeriodOfValidity(null);
            }
            //获取传来的门店id数组
            List<Integer> storeId = param2.getStoreId();
            //转化为字符串存储到数据库
            String storeIds = StringUtils.join(storeId, ",");
            param2.setGoodsAssignmentStore(storeIds);

            // 获取goods_base,赋值commomid
            List<ManageGdsBaseAddPublishDTO> gdsBases;
            if (null == param2.getGdsBases()) {
                gdsBases = new ArrayList<>();
            } else {
                gdsBases = param2.getGdsBases();
            }
            for (int k = 0; k < gdsBases.size(); k++) {
                ManageGdsBaseAddPublishDTO gdsBase = gdsBases.get(k);
                gdsBase.setGoodsPromotionTips(param2.getCommonPromotionTips());
                gdsBase.setShopId(shopId);
                gdsBase.setShopName(shopBaseQueryResult.getShopName());
                gdsBase.setGoodsIsRecommend(param2.getCommonIsRecommend());
                if (!param2.getGoodsImages().isEmpty() && k < param2.getGoodsImages().size()
                        && !param2.getGoodsImages().get(k).getMerchantGoodsImages().isEmpty()) {
                    gdsBase.setGoodsImage(param2.getGoodsImages().get(k).getMerchantGoodsImages().get(0).getImagesImage());
                } else {
                    gdsBase.setGoodsImage(null);
                }

                if (gdsBase.getBrandId() == null) {
                    gdsBase.setBrandId(0);
                }
                if (gdsBase.getGoodsAlarm() == null) {
                    gdsBase.setGoodsAlarm(0);
                }
                if (gdsBase.getGoodsMaxSale() == null) {
                    gdsBase.setGoodsMaxSale(0);
                }

                ManageGdsBaseAddParamvDTO manageGdsBaseAddParam = new ManageGdsBaseAddParamvDTO();
                manageGdsBaseAddParam.setSpecId(gdsBase.getSpecId());
                manageGdsBaseAddParam.setTypeId(gdsBase.getTypeId());
                //商品规格
                List<GoodBaseSpecValuesJsonBeanDTO> specValues;
                if (null == gdsBase.getSpecValues()) {
                    specValues = new ArrayList<>();
                } else {
                    specValues = gdsBase.getSpecValues();
                }
                String goodsSpec = null;
                for (GoodBaseSpecValuesJsonBeanDTO specValue : specValues) {
                    if (goodsSpec == null) {
                        goodsSpec = specValue.getParamValue();
                        continue;
                    }
                    goodsSpec = goodsSpec + "+" + specValue.getParamValue();
                }
                manageGdsBaseAddParam.setGoodsSpec(goodsSpec);
                System.out.println(goodsSpec);
                if (StringUtils.isNotBlank(gdsBase.getGoodsSpec())) {
                    manageGdsBaseAddParam.setGoodsName(" " + param2.getBrandName() + " " + gdsBase.getGoodsName() + " " + gdsBase.getGoodsSpec() + " ");
                } else {
                    manageGdsBaseAddParam.setGoodsName(" " + param2.getBrandName() + " " + gdsBase.getGoodsName() + " " + goodsSpec + " ");
                }
                manageGdsBaseAddParam.setShopId(gdsBase.getShopId());
                manageGdsBaseAddParam.setShopName(gdsBase.getShopName());
                manageGdsBaseAddParam.setGoodsPromotionTips(gdsBase.getGoodsPromotionTips());
                manageGdsBaseAddParam.setCatId(gdsBase.getCatId());
                manageGdsBaseAddParam.setGoodsSpecValue(gdsBase.getGoodsSpecValue());
                manageGdsBaseAddParam.setGoodsPrice(gdsBase.getGoodsPrice());
                manageGdsBaseAddParam.setGoodsMarketPrice(gdsBase.getGoodsMarketPrice());
                manageGdsBaseAddParam.setGoodsStock(gdsBase.getGoodsStock());
                //添加门店库存总和最大值
                manageGdsBaseAddParam.setGoodsShopGateStock(gdsBase.getGoodsShopGateStock());
                manageGdsBaseAddParam.setGoodsAlarm(gdsBase.getGoodsAlarm());
                manageGdsBaseAddParam.setGoodsCode(gdsBase.getGoodsCode());
                manageGdsBaseAddParam.setGoodsBarcode(gdsBase.getGoodsBarcode());
                manageGdsBaseAddParam.setGoodsIsRecommend(gdsBase.getGoodsIsRecommend());
                manageGdsBaseAddParam.setGoodsImage(gdsBase.getGoodsImage());
                manageGdsBaseAddParam.setGoodsIsShelves(gdsBase.getGoodsIsShelves());
                manageGdsBaseAddParam.setBrandId(gdsBase.getBrandId());
                manageGdsBaseAddParam.setGoodsCubage(gdsBase.getGoodsCubage());
                manageGdsBaseAddParam.setGoodsBabyPrice(gdsBase.getGoodsBabyPrice());
                manageGdsBaseAddParam.setGoodsMinSale(gdsBase.getGoodsMinSale());
                //规格跟着商品走
                manageGdsBaseAddParam.setIsUse(gdsBase.getIsUse());
                // 商家编号
                manageGdsBaseAddParam.setMerchantCode(gdsBase.getMerchantCode());
                // 商品编码
                manageGdsBaseAddParam.setCommodityBarTypeCode(gdsBase.getCommodityBarTypeCode());
                // 规格
                if (null != gdsBase.getSpecValues()) {
                    manageGdsBaseAddParam.setSpecValue(JSON.toJSONString(gdsBase.getSpecValues()));
                }
                //指导价
                manageGdsBaseAddParam.setHotPrice(gdsBase.getHotPrice());
                // 体积
                if (StringUtils.isNotEmpty(gdsBase.getGoodsVolume())) {
                    BigDecimal goodsVolume = new BigDecimal(gdsBase.getGoodsVolume());
                    manageGdsBaseAddParam.setGoodsVolume(goodsVolume);
                }
                // 商品成本价
                if (null != param2.getCommonCostPrice()) {
                    manageGdsBaseAddParam.setGoodsCostPrice(param2.getCommonCostPrice());
                }
                // 直播卖点
                if (StringUtils.isNotEmpty(param2.getSellingPoint())) {
                    manageGdsBaseAddParam.setSellingPoint(param2.getSellingPoint());
                }
                // 是否寄样
                if (null != gdsBase.getGoodsSendBack()) {
                    manageGdsBaseAddParam.setGoodsSendBack(gdsBase.getGoodsSendBack());
                }
                //限购不设置 则默认最多购买数量是商品的库存
                manageGdsBaseAddParam.setGoodsMaxSale(gdsBase.getGoodsMaxSale());
                if (null == gdsBase.getGoodsMaxSale() || 0 == gdsBase.getGoodsMaxSale()) {
                    manageGdsBaseAddParam.setGoodsMaxSale(gdsBase.getGoodsStock());
                }
                if (null != gdsBase.getCommission()) {
                    manageGdsBaseAddParam.setCommission(gdsBase.getCommission());
                }
                manageGdsBaseAddParam.setMoq(gdsBase.getMoq());
                manageGdsBaseAddParam.setTaxInclusiveAmount(gdsBase.getTaxInclusiveAmount());
                if (gdsBase.getTaxRate() != null) {
                    manageGdsBaseAddParam.setTaxRate(gdsBase.getTaxRate() * 0.01);
                }
                manageGdsBaseAddParam.setDw(param2.getDw());

                if (gdsBase.getIsEnquiry() != null && gdsBase.getIsEnquiry() == true) {
                    manageGdsBaseAddParam.setEnquiry(1);
                    manageGdsBaseAddParam.setIsEnquiry(true);
                } else {
                    manageGdsBaseAddParam.setEnquiry(0);
                    manageGdsBaseAddParam.setIsEnquiry(false);
                }

            }
            String paramString = JSON.toJSONString(param.get("draftContent"));
            if (StringUtils.isEmpty(draftName)) {
                draftName = "草稿_类目_" + param2.getCatName();
            }
            this.baseMapper.insertDraft(shopId, param2.getCatId(), draftName, paramString);
            return ResponseResult.success(1,BizCodeEnume.OPERATION_SUCCESSFUL.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.fail(BizCodeEnume.OPERATION_FAILED);
        }

    }
}
